package gui;

import processing.core.PApplet;

public class ParallelCoordinatesPlotLine {

	private PApplet mainApplet;
	private int[][] controlPoints;
	private Point[] visualPoints;
	private int baseColor;
	private int selectedColor;
	private boolean isSelected;
	
	public ParallelCoordinatesPlotLine(PApplet mainApplet, int[][] points, int baseColor, int selectedColor)
	{
		this.mainApplet = mainApplet;
		this.controlPoints = points;
		this.visualPoints = new Point[controlPoints.length];
		this.baseColor = baseColor;
		this.selectedColor = selectedColor;
		for(int i = 0; i < controlPoints.length; i++)
		{
			visualPoints[i] = new Point(i, controlPoints[i][0], controlPoints[i][1], this.baseColor, mainApplet);
			visualPoints[i].setHiglighted();
		}
	}
	
	public void setCurrentColor(int currentColor)
	{
		this.selectedColor = currentColor;
	}
	
	public void drawLine()
	{
		int startX = controlPoints[0][0];
		int startY = controlPoints[0][1];
		int endX = 0;
		int endY = 0;
		
		boolean noneSelected = true;
		for(Point p : visualPoints)
		{
			if(p.overPoint())
			{
				isSelected = true;
				noneSelected = false;
			}
		}
		if(noneSelected)
		{
			isSelected = false;
		}
		for(Point p : visualPoints)
		{
			if(isSelected)
			{
				p.setColor(selectedColor);
				p.setSelected();
				p.drawPoint();
			}
			else
			{
				p.setColor(baseColor);
				p.setUnselected();
				p.drawPoint();
			}
		}
		
		
		for(int i = 1; i < controlPoints.length; i++)
		{
			endX = controlPoints[i][0];
			endY = controlPoints[i][1];
			if(isSelected)
			{
				mainApplet.stroke(selectedColor);
				mainApplet.strokeWeight(4);
			}
			else
			{
				mainApplet.stroke(baseColor);
				mainApplet.strokeWeight(1);
			}
			mainApplet.line(startX, startY, endX, endY);
			startX = endX;
			startY = endY;
		}
		
	}
}
